#include "head.h"

void *sqlite_handler(void *arg)
{
	struct sqlite3 * pdb = sql_stockinfo_init("stockdb");	
	struct linkmsg lmsg = {0};
	((struct storage_info*)&(lmsg.text))->s_house_no = 1;
	insert_stocktable(pdb, (struct storage_info*)&(lmsg.text));
	
	select_stockdb(pdb, (struct storage_info *)&(lmsg.text));
	select_db(pdb);

	int stock_no = 0;
	while (1)
	{
		pthread_mutex_lock (&mutex.mutex_sqlite);
		while ( is_empty_linkqueue(link_db) )
		{
			pthread_cond_wait(&cond.cond_sqlite, &mutex.mutex_sqlite);
		}
		pthread_mutex_lock(&mutex.mutex_link_db);
		output_linkqueue(link_db, &lmsg);
		pthread_mutex_unlock(&mutex.mutex_link_db);
		printf("lmsg.type = %ld\n", lmsg.type);
		switch (lmsg.type)
		{
			case C_LOGIN:

 				break;
			case C_REGISTER:

				break;
			case C_ENV:
				printf("%s %s %d\n", __FILE__, __func__, __LINE__);
					updata_stocktable(pdb, (struct storage_info*)&(lmsg.text));
					select_db(pdb);
				break;
			default:
				break;
		}	

		pthread_mutex_unlock(&mutex.mutex_sqlite);
	}
}
